package se.liu.oschi129.game.levels.level01;

import se.liu.johfa428.levelstate.LevelState;
import se.liu.oschi129.animation.animationspace.AnimationSpace;
import se.liu.oschi129.game.objects.*;
import se.liu.oschi129.game.objects.blocks.breakable.*;
import se.liu.oschi129.game.objects.blocks.solid.*;
import se.liu.oschi129.game.objects.enemies.*;
import se.liu.oschi129.game.objects.items.*;
import se.liu.oschi129.game.objects.platforms.*;
import se.liu.oschi129.level.levelspace.LevelInterface;
import se.liu.oschi129.world.model.*;

/**
 * This is a level.
 * 
 * @author oschi129
 */
public class Level01 implements LevelInterface {

	public void createWorld(World world, LevelState levelState) {
		
		// Set the startup settings for the world
		world.setWidth(2400);
		world.setHeight(328);
		world.setTime(180);
		
		// Set the physical rules
		world.setPhysicalRules(new WorldPhysicalRules());
		
		// Add a statusbar
		world.addObjectSynchronized(new ObjectStatusBar(world));
		
		// Add a background
		world.addObjectSynchronized(new ObjectBackground(world,true,false,AnimationSpace.get("img_background03"),0,0));
		
		// Add a player to the world
		ObjectPlayer player;

		player = new ObjectPlayer(16,328-64);
		player.setPhysicalRules(world.getPhysicalRules());
		world.addObjectSynchronized(player);
		world.addInteractiveObjectSynchronized(player);
		
		// Set the world view to follow the player
		world.setView(new WorldView(256,222,player));
		
		// Add some solids to the world
			
		for (double x = 0; x < 256; x+= 16) {
			world.addObjectSynchronized(new ObjectBlock01(true, x, 296));
			world.addObjectSynchronized(new ObjectBlock01(true, x, 312));
		}
		
		// Add some container blocks
		ObjectBlock container;
		
		container = new ObjectBlock04(true, 64, 248);
		container.addContent(new ObjectCoin(0,0));
		world.addObjectSynchronized(container);
		
		container = new ObjectBlock04(true, 144, 248);
		container.addContent(new ObjectPowerupMushroom(0,0));
		world.addObjectSynchronized(container);
		
		container = new ObjectBlock04(true, 176, 248);
		container.addContent(new ObjectCoin(0,0));
		world.addObjectSynchronized(container);
		
		container = new ObjectBlock04(true, 160, 184);
		for (double n = 0; n < 8; n++)
			container.addContent(new ObjectCoin(0,0));
		world.addObjectSynchronized(container);
		
		// Add some bricks
		world.addObjectSynchronized(new ObjectBreakableBlock09(true, 128, 248));
		world.addObjectSynchronized(new ObjectBreakableBlock09(true, 160, 248));
		world.addObjectSynchronized(new ObjectBreakableBlock09(true, 192, 248));
		
		for (double x = 304; x < 480; x+= 16) {
			if (x >= 400)
				world.addObjectSynchronized(new ObjectBlock01(true, x, 280));
			world.addObjectSynchronized(new ObjectBlock01(true, x, 296));
			world.addObjectSynchronized(new ObjectBlock01(true, x, 312));
		}
		
		// Add a platform
		world.addObjectSynchronized(new ObjectStaticPlatform03(320, 232));
		world.addObjectSynchronized(new ObjectBackground(world,false,false,AnimationSpace.get("img_platform_base01"),352,248));
		world.addObjectSynchronized(new ObjectBackground(world,false,true,AnimationSpace.get("img_platform_base02"),352,264));
		

		for (double x = 512; x < 640; x+= 16) {
			world.addObjectSynchronized(new ObjectBlock01(true, x, 280));
			world.addObjectSynchronized(new ObjectBlock01(true, x, 296));
			world.addObjectSynchronized(new ObjectBlock01(true, x, 312));
		}
		
		// Add a platform
		world.addObjectSynchronized(new ObjectStaticPlatform03(528, 216));
		world.addObjectSynchronized(new ObjectBackground(world,false,false,AnimationSpace.get("img_platform_base01"),560,232));
		world.addObjectSynchronized(new ObjectBackground(world,false,true,AnimationSpace.get("img_platform_base02"),560,248));
		
		container = new ObjectBlock04(true, 560, 160);
		for (double n = 0; n < 8; n++)
			container.addContent(new ObjectCoin(0,0));
		world.addObjectSynchronized(container);
		
		// Add a movable platform between the solids
		ObjectMovablePlatformCollider collider;
		collider = new ObjectMovablePlatformCollider(624, 280, 16,16);
		collider.setHorizontalSpeed(2);
		world.addObjectSynchronized(collider);
		
		collider = new ObjectMovablePlatformCollider(800, 280, 16,16);
		collider.setHorizontalSpeed(-2);
		world.addObjectSynchronized(collider);
		
		ObjectMovablePlatform platform;
		
		platform = new ObjectMovablePlatform(640, 280, 49, 9);
		platform.setAnimation(AnimationSpace.get("img_platform01"));
		platform.setVisible(true);
		platform.setHorizontalSpeed(2);
		world.addObjectSynchronized(platform);
		
		// Create some more solids
		for (double x = 800; x < 1024; x+= 16) {
			world.addObjectSynchronized(new ObjectBlock01(true, x, 280));
			world.addObjectSynchronized(new ObjectBlock01(true, x, 296));
			world.addObjectSynchronized(new ObjectBlock01(true, x, 312));
		}
		
		// Add a platform
		world.addObjectSynchronized(new ObjectStaticPlatform03(816, 216));
		world.addObjectSynchronized(new ObjectBackground(world,false,false,AnimationSpace.get("img_platform_base01"),848,232));
		world.addObjectSynchronized(new ObjectBackground(world,false,true,AnimationSpace.get("img_platform_base02"),848,248));
		
		// Add a coin
		world.addObjectSynchronized(new ObjectCoin(true, 848,200));
		
		// Add a platform
		world.addObjectSynchronized(new ObjectStaticPlatform02(960, 160));
		world.addObjectSynchronized(new ObjectBackground(world,false,false,AnimationSpace.get("img_platform_base01"),976,176));
		world.addObjectSynchronized(new ObjectBackground(world,false,true,AnimationSpace.get("img_platform_base02"),976,192));
		
		// Add a coin
		world.addObjectSynchronized(new ObjectCoin(true, 976,144));
		
		for (double y = 160; y < 328; y+= 16) {
			world.addObjectSynchronized(new ObjectBlock01(true, 1104, y));
			world.addObjectSynchronized(new ObjectBlock01(true, 1120, y));
			world.addObjectSynchronized(new ObjectBlock01(true, 1136, y));
		}
		
		// Add some more coins
		container = new ObjectBlock04(true, 1120, 112);
		for (double n = 0; n < 8; n++)
			container.addContent(new ObjectCoin(0,0));
		world.addObjectSynchronized(container);
		
		// Add a platform between the solids
		collider = new ObjectMovablePlatformCollider(1056, 160, 16,16);
		collider.setVerticalSpeed(2);
		world.addObjectSynchronized(collider);

		collider = new ObjectMovablePlatformCollider(1056, 296, 16,16);
		collider.setVerticalSpeed(-2);
		world.addObjectSynchronized(collider);
		
		platform = new ObjectMovablePlatform(1048, 280, 49, 9);
		platform.setAnimation(AnimationSpace.get("img_platform01"));
		platform.setVisible(true);
		platform.setVerticalSpeed(-2);
		world.addObjectSynchronized(platform);
		
		// Create some more solids
		for (double x = 1152; x < 1472; x+= 64) {
			world.addObjectSynchronized(new ObjectBlock01(true, x, 160));
			world.addObjectSynchronized(new ObjectBlock01(true, x+16, 160));
		}
		
		for (double x = 1168; x < 1488; x+= 64) {
			world.addObjectSynchronized(new ObjectBlock01(true, x, 264));
			world.addObjectSynchronized(new ObjectBlock01(true, x+16, 264));
			// Add some coins
			world.addObjectSynchronized(new ObjectCoin(true, x+8, 248));
		}
		
		// Add a platform below the solids
		collider = new ObjectMovablePlatformCollider(1136, 312, 16,16);
		collider.setHorizontalSpeed(2);
		world.addObjectSynchronized(collider);

		collider = new ObjectMovablePlatformCollider(1536, 312, 16,16);
		collider.setHorizontalSpeed(-2);
		world.addObjectSynchronized(collider);

		platform = new ObjectMovablePlatform(1152, 312, 49, 9);
		platform.setAnimation(AnimationSpace.get("img_platform01"));
		platform.setVisible(true);
		platform.setHorizontalSpeed(2);
		world.addObjectSynchronized(platform);
		
		for (double x = 1168; x < 1488; x+=32)
			world.addObjectSynchronized(new ObjectCoin(true, x, 296));
		
		// Add some more solids
		for (double x = 1536; x < 2400; x+= 16) {
			world.addObjectSynchronized(new ObjectBlock01(true, x, 280));
			world.addObjectSynchronized(new ObjectBlock01(true, x, 296));
			world.addObjectSynchronized(new ObjectBlock01(true, x, 312));
		}
		
		// Add some bricks
		for (double x = 1600; x < 1920; x+=16) {
			if (x > 1632)
				world.addObjectSynchronized(new ObjectBreakableBlock10(true, x, 160));
			if (x < 1904)
			world.addObjectSynchronized(new ObjectBreakableBlock10(true, x, 224));
			else {
				// Add a "secret" powerup
				container = new ObjectBlock10(true, 1904, 224);
				container.addContent(new ObjectPowerupSpike(0,0));
				world.addObjectSynchronized(container);
			}
		}
		
		// Add a mini-boss
		world.addObjectSynchronized(new ObjectEnemyToadThrowing(2160,328-48-32));
		world.addObjectSynchronized(new ObjectEnemyToadCollider(2000,328-48-64,16,64));
		world.addObjectSynchronized(new ObjectEnemyToadCollider(2240,328-48-64,16,64));
		
		// Add some enemies
		world.addObjectSynchronized(new ObjectEnemyBird(480,160));
		world.addObjectSynchronized(new ObjectEnemyBird(640,240));
		world.addObjectSynchronized(new ObjectEnemyBird(800,200));
		world.addObjectSynchronized(new ObjectEnemyBird(960,240));
		world.addObjectSynchronized(new ObjectEnemyBird(1120,160));
		world.addObjectSynchronized(new ObjectEnemyBird(1280,200));
		world.addObjectSynchronized(new ObjectEnemyBird(2000,180));
		world.addObjectSynchronized(new ObjectEnemyBird(2000,240));
		
		world.addObjectSynchronized(new ObjectGoal(levelState, 2368,328-176-48));
		
		
	}
	
}
